<template>
<div>
  <Card>
    <Collapse style="margin-bottom:15px;">
      <Panel>查询
        <div slot="content">
          <Form
            ref="formLkyApplyAdmin"
            :model="formLkyApplyAdmin"
            label-position="right"
            :label-width="80"
            inline
          >
            <!--学院、专业、班级查询-->
           
            <FormItem label="所属学院" prop="name1">
            	<Select v-model="coid" style="width:200px" @on-open-change="onOpenChangeCollege" @on-change="onOpenChangeMajor" clearable >
            		<Option v-for="item in collegeList" :value="item.id" :key="item.id">
            			{{ item.name }}
            		</Option>
            	</Select>
            </FormItem>
            <FormItem label="所属专业" prop="name2">
            	<Select v-model="mid" style="width:200px" @on-change="onOpenFindClassByMid" clearable >
            		<Option v-for="item in majorList" :value="item.id" :key="item.id">
            			{{ item.name }}
            		</Option>
            	</Select>
            </FormItem>
            <FormItem label="所属班级" prop="name3">
            	<Select v-model="cid" style="width:200px" clearable >
            		<Option v-for="item in classList" :value="item.id" :key="item.id" >
            			{{ item.name }}
            		</Option>
            	</Select>
            </FormItem>
            <FormItem>
              <Button type="primary" @click="handleSubmit('formLkyApplyAdmin')">查询</Button>
              <Button @click="handleReset('formLkyApplyAdmin')" style="margin-left: 8px">重置</Button>
            </FormItem>
          </Form>
        </div>
      </Panel>
    </Collapse>

    <Table
      ref="tableLkyApplyAdmin"
      :data="tableData"
      :columns="columns"
      @on-selection-change="onSelectionChange"
      @on-sort-change="onSortChange"
    />
    <div style="margin: 10px;overflow: hidden">
      <div style="float: right;">
        <Page
          :total="total"
          :current="current"
          :page-size="pageSize"
          @on-page-size-change="changePageSize"
          @on-change="changePage"
          :show-total="true"
          show-sizer
        ></Page>
      <Edit v-model="isOpenEditPage" @updateRow="updateLkyApplyAdmin"  :LkyApplyAdmin="editLkyApplyAdmin"/>

      </div>
    </div>

  </Card>
</div>
</template>

<script>
import { list , update,} from '@/api/lky/lkyApplyAdmin'
import { createFormObj, createModelObj } from '@/libs/util'

// 学院查询、专业、班级查询
	import {
		queryAll
	} from '@/api/lky/lkyCollege'
	import {
		queryAllM
	} from '@/api/lky/lkyMajor'
	import {
		queryFindClassByMid
	} from '@/api/lky/lkyClass'

import Edit from './edit.vue'

export default {
  name: 'LkyApplyAdmin',
  components: {
    Edit
  },
  data ()  {
    return {

	    editLkyApplyAdmin: null ,
	    isOpenEditPage:false ,
	    isOpenUpdate: false ,

      formLkyApplyAdmin: {
        id: '',
        USER_NAME: '',
        file_name: '',
        name1: '',
        name2: '',
		    reate_time:'',
		    name3:'',
		    remark_info:'',
        creation_time: ''

      },
      columns: [
      
        {key: 'USER_NAME', title: '学生', sortable: true},
        {key: 'file_name', title: '表名', sortable: true},
        {key: 'name1', title: '班级', sortable: true},
        {key: 'name2', title: '专业', sortable: true},
        {key: 'name3', title: '学院', sortable: true},
        {key: 'creation_time', title: '申请时间', sortable: true},
        {
          title: '操作',
          key: 'action',
          width: 250,
          align: 'center',
          render: (h, params) => {
            return h('div', [
              h(
                'Button',
                {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    marginRight: '5px'
                  },
                  on: {
                    click: () => {
                      this.editLkyApplyAdmin = params.row
                      this.handleOpenPage('edit')

                    }
                  }
                },
                '查看'
              ),
              h(
                'Button',
                {
                  props: {
                    type: 'error',
                    size: 'small'
                  },
                  on: {
                    click: () => {
                      var obj = {}
                      obj.id = params.row.id
                      update(Object.assign({}, createModelObj(obj, 'lkyApplyRecord'))).then(res => {
                      })
                      this.getLkyApplyList(this.current, this.pageSize)
                    }
                  }
                },
                '通过'
              )
            ])
          }
        }
      ],
      tableData: [],
      total: 0,
      current: 1,
      pageSize: 10,
      selection: [],
	  // 创建容器
	  coid: '',
	  mid: '',
	  cid: '',
	  collegeList: [],
	  majorList: [],
	  classList: []
    }
  },
  methods: {
  onOpenChangeCollege() {
  	queryAll().then(res => {
  		this.collegeList = res.data
  	})
  },
  onOpenChangeMajor(coid) {
  	this.cid = ''
  	this.mid = ''
  	queryAllM({
  		'coid': this.coid
  	}).then(res => {
  		this.majorList = JSON.parse(JSON.stringify(res.data))
  	})
  },
  onOpenFindClassByMid(mid) {
  	
  	queryFindClassByMid({
  		'mid': this.mid
  	}).then(res => {
  		this.classList = JSON.parse(JSON.stringify(res.data))
  	})
  },
    handleSubmit (name) {
      // 查询按钮事件
      this.getLkyApplyList(this.current, this.pageSize)
      this.$Message.success('Success!')
    },
    handleReset (name) {
		this.coid = ''
		this.mid = ''
		this.cid = ''
		// 重置按钮事件
		this.$refs[name].resetFields()
    },
    handleOpenPage (name) {
      // 打开页面事件(添加页,编辑页...)
      // === 是地址相同
      // == 是值相同
	  
      if (name == 'add') this.isOpenUpdate = true
      else if (name == 'edit') {
        this.isOpenEditPage = true
      }
    },
    updateLkyApplyAdmin (row) {
      this.$set(this.update, row.id, row)
    },

 
    getLkyApplyList (current, pageSize, paras) {
      let para = { pageNumber: current, pageSize: pageSize }
      if (paras) Object.assign(para, paras)
	 // key-value放入传入后端
	 Object.assign(para, {
	 	coid: this.coid,
	 	mid: this.mid,
	 	cid: this.cid,
	 	
	 })
      list(this.handleRequestParams(para)).then(res => {
        this.tableData = res.list
        this.current = parseInt(res.pageNumber)
        this.pageSize = parseInt(res.pageSize)
        this.total = parseInt(res.totalRow)
      })
    },
	
    handleRequestParams (para) {
      Object.assign(para, createFormObj(this.formLkyApplyAdmin, 'lkyClass'))
      // 后端还需要coid 数据，coid不属于 lkyClass
      Object.assign(para, { coid: this.coid })
    
      return para
    },
    exportExcel () {
      this.$refs.tableLkyClass.exportCsv({
        filename: `table-${new Date().valueOf()}.csv`
      })
    },
    changePage (pageNumber) {
      this.getLkyApplyList(pageNumber, this.pageSize)
    },
    changePageSize (pageSize) {
      this.getLkyApplyList(this.current, pageSize)
    },
    remove (index) {
      this.data6.splice(index, 1)
    },
    onSelectionChange (selection) {
      this.selection = selection
    },
    onSortChange (obj) {
      if (obj.order === 'normal') {
        this.getLkyApplyList(1, this.pageSize)
      } else {
        this.getLkyApplyList(1, this.pageSize, {
          field: obj.key,
          order: obj.order
        })
      }
    }
  },

  mounted () {
    this.getLkyApplyList(this.current, this.pageSize)
	
  }
}
</script>

<style>
</style>

